using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

[Serializable]
public class RepelEffectComponent : TakeDamageEffectBaseComponent
{
    public GameObject RepelGameObject;
    public float knockbackForce = 5;//被击退力量
    public float knockBackTime = 0.2f; //被击退的持续时间
    public override void TakeDamageEffectPlay(GameObject AttackObject)
    {
        base.TakeDamageEffectPlay(AttackObject);
        if (RepelGameObject != null)
        {
            // 计算从攻击者（玩家）到怪物的方向
            Vector3 knockbackDirection = (RepelGameObject.transform.position - AttackObject.transform.position).normalized;
            knockbackDirection.y = 0; // 保持在水平面上

            // 直接移动位置实现击退
            // transform.position += knockbackDirection * knockbackForce;
            RepelGameObject.transform.DOMove(RepelGameObject.transform.position + knockbackDirection * knockbackForce, 0.2f).SetEase(Ease.OutQuad);
        }
    }
}
